/** 每页显示条数下拉选择框 */
var states = Ext.create('Ext.data.Store', {
	fields : [ 'value', 'text' ],
	data : [ {
		'value' : "10",
		'text' : "10条/页"
	}, {
		'value' : "20",
		'text' : "20条/页"
	}, {
		'value' : "30",
		'text' : "30条/页"
	}, {
		'value' : "50",
		'text' : "50条/页"
	}, {
		'value' : "100",
		'text' : "100条/页"
	}, {
		'value' : "200",
		'text' : "200条/页"
	} ]
});

Ext.define('configCenter.pageSizeCombo', {
	extend : 'Ext.form.ComboBox',
	alias : 'widget.pageSizeCombo',
	name : 'pagesize',
	displayField : 'text',
	valueField : 'value',
	store : states,
	editable : false,
	value : '10',
	width : 85
});

var Common = {
	ajaxRequest : function(setting) {
		var params = setting.params === undefined ? {} : setting.params;
		var showWaiting = setting.showWaiting === undefined ? true : setting.showWaiting;
		var showMsg = setting.showMsg === undefined ? true : setting.showMsg;
		var timeout = setting.timeout === undefined ? 60 * 1000 : setting.timeout;
		// 发送请求
		waiting = null;
		if (showWaiting) {
			waiting = Ext.Msg.wait('正在处理，请稍等...', '', '');
		}
		Ext.Ajax.request({
			url : setting.url,
			params : params,
			timeout : timeout,
			method : 'post',
			success : function(response, options) {
				if (waiting != null) {
					waiting.hide();
				}
				var json = Ext.decode(response.responseText);
				if (json.success == true) {
					if (showMsg == true) {
						var successMsg = '操作成功.';
						if (json.msg && json.msg != '') {
							successMsg = json.msg;
						} else if (setting.successMsg
								&& setting.successMsg != '') {
							successMsg = setting.successMsg;
						}
						Ext.Msg.alert('提示', successMsg, function() {
							if (setting.callback) { // 回调方法
								setting.callback(json);
							}
						});
					} else {
						if (setting.callback) { // 回调方法
							setting.callback(json);
						}
					}
				} else if (json.success == false) {
					Ext.Msg.alert("提示", json.msg);
				}
			}
		});
	}
}
